I am trying to reduce fractions.
If I replace double by int,there is no error,and it will run answers. But the wrong one.....
I don't know if I use the reducing fractions' rule wrongly.
Can someone help me pleaseQQ
If I replace double by int,there is no error,and it will run answers. But the wrong one.....
I don't know if I use the reducing fractions' rule wrongly.
Can someone help me pleaseQQ
Code:
RationalNumber::RationalNumber(double a,double b) { if(b>0)//prvent deno<0 { double r; if(a<0)//if nume<0 { a=-a; r=(a%b); while(r!=0) { a=b; b=r; r=a%b; } this->nume=-a; this->deno=b; cout<<"test2"<<nume<<"/"<<deno<<endl; } else { r=a%b; while(r!=0) { a=b; b=r; r=a%b; } this->nume=a; this->deno=b; cout<<"test2"<<nume<<"/"<<deno<<endl; } } else { cout<<"It's a invalid fraction."<<endl; cout<<"The fraction will be set to 0/1"<<endl; this->nume=0; this->deno=1; cout<<"test2"<<nume<<"/"<<deno<<endl; } }
Comment